package ru.disa.blog.post.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ru.disa.blog.post.Post;
import ru.disa.blog.post.PostId;
import ru.disa.blog.post.PostRepository;

public class InMemoryPostRepository implements PostRepository {
  private Map<PostId, Post> identityMap = new HashMap<PostId, Post>();

  @Override
  public Post get(PostId postId) {
    return this.identityMap.get(postId);
  }

  @Override
  public List<Post> getAll() {
    return new ArrayList<Post>(this.identityMap.values());
  }

  @Override
  public void add(Post post) {
    PostId postId = new PostId();
    post.setPostId(postId);
    this.identityMap.put(postId, post);
  }

  @Override
  public void remove(PostId postId) {
    this.identityMap.remove(postId);
  }
}
